package com.等待唤醒机制.阻塞队列来实现等待唤醒机制;


import java.util.concurrent.ArrayBlockingQueue;

public class Foodie extends Thread{
    ArrayBlockingQueue<String> queue;

    public Foodie(ArrayBlockingQueue<String> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true){
            //不断把面条取出阻塞队列中
            try {
                String food = queue.take();//取出来
                System.out.println(food+"吃了一碗面条");
                //打印在锁外面不影响结果，但是打印会出问题不碍事

                //不用加锁,外面加了锁里面也有所就是锁的嵌套，会死锁
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
